package com.cy.aircompressor.config;

import android.text.TextUtils;

import com.cy.aircompressor.entity.select.SelectDict;
import com.cy.aircompressor.entity.system.SysConfig;
import com.cy.aircompressor.entity.system.UserInfo;

import java.util.List;

public class AirConfig {
    private static class SingletonHolder {
        private static final AirConfig INSTANCE = new AirConfig();
    }

    public static AirConfig get() {
        return SingletonHolder.INSTANCE;
    }

    public boolean loginFlag = false;
    public UserInfo userInfo;
    public SysConfig sysConfig;
    //空压机部位
    public List<SelectDict> compressorParts;
    //空压机点位
    public List<SelectDict> compressorPoints;
    //采集器通道
    public List<SelectDict> collectorChannels;
    //空压机
    public List<SelectDict> compressors;
    //电站
    public List<SelectDict> powerStations;
    //传感器范围
    public List<SelectDict> sensorRanges;
    //传感器类型
    public List<SelectDict> sensorTypes;

    public boolean isLoginFlag() {
        return loginFlag;
    }

    public void updateLoginFlag(boolean loginFlag) {
        this.loginFlag = loginFlag;
    }

    public void updateUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }

    public void updateSysConfig(SysConfig sysConfig) {
        this.sysConfig = sysConfig;
    }

    public void updateCompressorPart(List<SelectDict> compressorParts) {
        this.compressorParts = compressorParts;
    }

    public void updateCompressorPoint(List<SelectDict> compressorPoints) {
        this.compressorPoints = compressorPoints;
    }

    public void updateCollectorChannels(List<SelectDict> collectorChannels) {
        this.collectorChannels = collectorChannels;
    }

    public void updateCompressors(List<SelectDict> compressors) {
        this.compressors = compressors;
    }

    public void updatePowerStations(List<SelectDict> powerStations) {
        this.powerStations = powerStations;
    }

    public void updateSensorRanges(List<SelectDict> sensorRanges) {
        this.sensorRanges = sensorRanges;
    }

    public void updateSensorTypes(List<SelectDict> sensorTypes) {
        this.sensorTypes = sensorTypes;
    }

    public String getSensorName(String sensorType) {
        if (sensorTypes == null) return "--";
        for (SelectDict selectDict : sensorTypes) {
            if (TextUtils.equals(selectDict.getValue(), sensorType)) {
                return selectDict.getLabel();
            }
        }
        return "--";
    }

    public void release() {
        loginFlag = false;
        userInfo = null;
        sysConfig = null;
        //空压机部位
        compressorParts = null;
        //空压机点位
        compressorPoints = null;
        //采集器通道
        collectorChannels = null;
        //空压机
        compressors = null;
        //电站
        powerStations = null;
        //传感器范围
        sensorRanges = null;
        //传感器类型
        sensorTypes = null;
    }
}
